<?php


class CompassAction extends Action{
	
	function getIP() {
		$limmit = isset($_REQUEST['limit'])?$_REQUEST['limit']:50;
		$limmit = min($limmit,400);
		$model = D('Agent');
		$time = time()-3600*24;//24小时
		$items	=	$model->field('agt_id,agt_ip,agt_port,agt_type,agt_rank,agt_lasttime,agt_err')->where("agt_lasttime + agt_err*3600*24 < $time and agt_rank<4 and agt_country='中国' and agt_province not in ('台湾','香港','澳门') AND (agt_rank>0 AND agt_err<8 OR agt_err < 3)")->order('agt_lasttime + agt_err*3600*24 ASC')->limit($limmit)->select();
		if ($items) {
			echo json_encode($items);
		}else {
			echo json_decode(0);
		}
	}
	
	function report() {
		echoJson($_REQUEST);
		//exit;
		$time = time();
		$model = D('Agent');
		foreach ($_REQUEST['report'] as $id=>$info){
			$data = array(
				'agt_id'=>$id,
				'agt_lasttime'	=>	$time,
				'agt_checktime'=>$time,
			);
			if (isset($info['rank'])) {
				$data['agt_rank'] = $info['rank'];
			}
			if (isset($info['success'])) {
				$data['agt_err']=0;
			}elseif (isset($info['err'])) {
				$data['agt_err']	=	array('exp','agt_err+1');
			}
			$model->save($data);
		}
	}
}